package com.xms.schema.service.attribute;

import com.xms.dependency.XmsDependencyException;
import com.xms.schema.event.EntityMetaDeletedEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

/**
 * <p>
 * 实体删除后，级联删除字段
 * </p>
 *
 * @author migo
 * @since 2021/10/26
 */
@Service
public class AttributeCascadeDeleter {
    private IAttributeDeleterService _attributeDeleterService;

    @Autowired
    public void AttributeCascadeDeleter(IAttributeDeleterService attributeDeleterService) {
        _attributeDeleterService = attributeDeleterService;
    }

    @Async
    @EventListener
    public void onApplicationEvent(EntityMetaDeletedEvent event) throws XmsDependencyException, SQLException {
        _attributeDeleterService.deleteByEntityId(event.source.getEntityid());
    }
}
